package com.wk.jetpackdemo.ui.main

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MediatorLiveData
import android.arch.lifecycle.ViewModel
import com.wk.jetpackdemo.db.AppDatabase
import com.wk.jetpackdemo.db.entities.User

class MainViewModel : ViewModel() {
    private val mData: MediatorLiveData<List<User>> = MediatorLiveData()

    init {
        mData.addSource(AppDatabase.Holder.INSTANCE.testUserDao.allUsers, mData::postValue)
    }

    fun getUsers(): LiveData<List<User>> {
        return mData
    }


    fun inserUsers(users: List<User>) {
        AppDatabase.Holder.INSTANCE.testUserDao.insert(users)
    }

}
